package com.buka.controller;

import com.buka.domain.ResponseResult;
import com.buka.dto.AddArticleDto;
import com.buka.pojo.Article;
import com.buka.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article) {
        return articleService.add(article);
    }

    @GetMapping("/list")
    public ResponseResult list(int pageNum, int pageSize, String title, String summary) {
        return articleService.list(pageNum, pageSize, title, summary);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleById(@PathVariable("id") int id) {
        return articleService.getArticleById(id);
    }

    @PutMapping
    public ResponseResult updateArticleById(@RequestBody Article article) {
        return articleService.updateArticleById(article);
    }
}
